package com.liy.framework.common.mybatis.rest;

import com.liy.framework.common.extvo.ResultVO;
import com.liy.framework.common.mybatis.entity.User;
import com.liy.framework.common.mybatis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/demo/user"})
public class UserController {
    @Autowired
    protected UserService baseBiz;

    public UserController() {
    }

    @RequestMapping(
            value = {"/test"},
            method = {RequestMethod.GET}
    )
    @ResponseBody
    public ResultVO add() {
        try {
            User entity = new User();
            entity.setId("id01");
            entity.setName("test01");
            entity.setAccount("admin01");
            this.baseBiz.insert(entity);
            return new ResultVO(true, "新增成功", "200", entity);
        } catch (Exception var2) {
            return new ResultVO(false, "新增时发生错误:" + var2.getMessage(), "500");
        }
    }

    @RequestMapping(
            value = {"/get/{id}"},
            method = {RequestMethod.GET}
    )
    @ResponseBody
    public ResultVO add(@PathVariable("id") int id) {
        try {
            this.baseBiz.selectById(id);
            return new ResultVO(true, "新增成功", "200", this.baseBiz.selectById(id));
        } catch (Exception var3) {
            return new ResultVO(false, "新增时发生错误:" + var3.getMessage(), "500");
        }
    }
}
